package top.lingkang.finalgateway.core.ssl;

import io.netty.channel.ChannelInitializer;
import io.netty.channel.ChannelPipeline;
import io.netty.channel.socket.SocketChannel;
import io.netty.handler.ssl.SslContext;
import lombok.extern.slf4j.Slf4j;
import top.lingkang.finalgateway.config.RouterConfig;

/**
 * @author lingkang
 * Created by 2024/5/5
 */
@Slf4j
public class SslServerInitHandler extends ChannelInitializer<SocketChannel> {
    public final RouterConfig config;
    public final SslConfig sslConfig;
    public final SslContext sslContext;

    public SslServerInitHandler(RouterConfig config, SslConfig sslConfig, SslContext sslContext) {
        this.config = config;
        this.sslConfig = sslConfig;
        this.sslContext = sslContext;
    }

    @Override
    protected void initChannel(SocketChannel ch) throws Exception {
        ChannelPipeline pipeline = ch.pipeline();
        pipeline.addLast(new RedirectToHttpsHandler(this));
    }
}
